package cn.agiledata.bank.linkbank.impl.ccb;

import java.math.BigDecimal;

import cn.agiledata.bank.linkbank.impl.AbstractBankNetPayRequest;
import cn.agiledata.bank.linkbank.impl.AbstractBankPayRequest;
import cn.agiledata.bank.linkbank.logic.DigitalSignGeneratable;

/**
 * 中国建设银行网上银行支付请求
 * 
 * @author 马贤波
 * 
 */
public final class CcbNetPayRequest extends AbstractBankNetPayRequest implements
        DigitalSignGeneratable {

    public CcbNetPayRequest() {
        super();
        init();
    }

    private void init() {
        setParameter(CcbNetConstant.CURRENCY_TYPE,
                CcbNetConstant.CURRENCY_TYPE_RMB); // 货币种类：人民币
        setParameter(CcbNetConstant.TX_CODE, CcbNetConstant.TX_CODE_UNIFORM); // 交易码：统一交易码
        setParameter(CcbNetConstant.REMARK2, ""); // 备注2
    }

    protected AbstractBankPayRequest getCopiedInstance() {
        return new CcbNetPayRequest();
    }

    public String getMerchantUrl() {
        return "";
    }

    public void setMerchantUrl(String merchantUrl) {
    }

    public void setMerchantId(String merchantId) {
        setParameter(CcbNetConstant.MERCHANT_ID, merchantId);
    }

    public void setPosId(String posId) {
        setParameter(CcbNetConstant.POS_ID, posId);
    }

    public void setBranchId(String branchId) {
        setParameter(CcbNetConstant.BRANCH_ID, branchId);
    }

    public void setAmount(BigDecimal amount) {
        setParameter(CcbNetConstant.AMOUNT, amount.setScale(2).toString());
    }

    public void setOrderId(String orderId) {
        setParameter(CcbNetConstant.ORDER_ID, orderId);
    }

    public void setRemark(String remark) {
        setParameter(CcbNetConstant.REMARK1, remark);
    }

    public String getSubmitMethod() {
        return SUBMIT_METHOD_GET;
    }

    public void setMac(String mac) {
        setParameter(CcbNetConstant.MAC, mac);
    }

    public String generateDigitalSign(String cryptoKey) {
        String[] keys = { CcbNetConstant.MERCHANT_ID,
                CcbNetConstant.POS_ID, CcbNetConstant.BRANCH_ID,
                CcbNetConstant.ORDER_ID, CcbNetConstant.AMOUNT,
                CcbNetConstant.CURRENCY_TYPE, CcbNetConstant.TX_CODE,
                CcbNetConstant.REMARK1, CcbNetConstant.REMARK2 };
        String mac = CcbUtils.generateMac(getParameters(), keys);
        setMac(mac);
        return mac;
    }

    public String getCryptoKeyDescription() {
        return null;
    }

    public boolean validateCryptoKey(String cryptoKey) {
        // 不需要密钥，始终返回true
        return true;
    }

}
